package com.murfrosost.airhockey.activities;

import com.murfrosost.airhockey.R;
import com.murfrosoft.airhockey.game.*;

import com.murfrosost.airhockey.R.layout;
import com.murfrosost.airhockey.R.menu;

import android.graphics.Point;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Build;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.WindowManager;

public class AirHockeyActivity extends Activity {

	AirHockeyGame2 airHockeyGame;
	
	int width;
	int height;
	MediaPlayer player;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		
		Point size = new Point();
		WindowManager w =   getWindowManager();
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
		  //manually disabled error
			w.getDefaultDisplay().getSize(size);
		      width = size.x;
		      height = size.y; 
		    }else{
		      android.view.Display d = w.getDefaultDisplay(); 
		      width = d.getWidth(); 
		      height = d.getHeight(); 
		    }
		player=MediaPlayer.create(this, R.raw.serious);
		player.setLooping(true);
		airHockeyGame = new AirHockeyGame2(this,width,height);
		setContentView(airHockeyGame);
		

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		airHockeyGame.stop();
		player.stop();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		airHockeyGame.go();
		player=MediaPlayer.create(this, R.raw.serious);
		player.setLooping(true);
		player.setOnPreparedListener(new OnPreparedListener() {
		    @Override
		    public void onPrepared(MediaPlayer mp) {
		        player.start();
		    }
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_air_hockey, menu);
		
		return true;
	}

}

